const path = require('path')
const resolve = dir => path.join(__dirname, dir)
const CompressionPlugin = require('compression-webpack-plugin')
// const fs = require('fs')

module.exports = {
    publicPath: './',
    runtimeCompiler: true,
    // 配置路径别名
    chainWebpack: config => {
        config.resolve.alias
            .set('@', resolve('src'))
            .set('_c', resolve('src/components/'))
            .set('_as', resolve('src/assets/img/'))

        config.plugin("html").tap(args => {
            args[0].title = '迈胜医疗'
            return args
        })
    },
    configureWebpack: {
        plugins: [
            new CompressionPlugin({
                test: /\.(js|css|png)?$/i, // 哪些文件要压缩
                filename: '[path].gz[query]',
                algorithm: 'gzip',
                minRatio: 1,
                deleteOriginalAssets: true // 删除未压缩的文件，谨慎设置，如果希望提供非gzip的资源，可不设置或者设置为false
            })
        ]
    },
    productionSourceMap: false,
    // rules:[{
    //     test: /\.less$/,
    //     use: ['style-loader', 'css-loader', 'less-loader', {
    //         loader: 'style-resources-loader',
    //         options: {
    //             patterns: path.resolve(__dirname, 'path/to/less/variables/*.less'),
    //             injector: 'append'
    //         }
    //     }]
    // }],
    // 传递第三方插件选项
    pluginOptions: {
        // 'AMap': 'AMap',
        // 'QRCode': 'QRCode'
    },
    // 全局注入通用样式
    css: {
        loaderOptions: {
            less: {
                globalVars: {
                  'theme-color': '#421466'
                }
              }
        }
    }
}
